package com.collectplus.express.city;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.collectplus.express.R;
import com.collectplus.express.model.CalculateProvinceBean;
import com.collectplus.express.model.ProvinceBean;

import java.util.ArrayList;
import java.util.List;

public class CityAdapter extends BaseAdapter {

    private List<ProvinceBean.Province> mArr;
    private LayoutInflater mInflater;

    public CityAdapter(Context context, List<ProvinceBean.Province> arr) {
        mArr = arr;
        if (mArr == null) {
            mArr = new ArrayList<>();
        }
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mArr.size();
    }

    @Override
    public Object getItem(int position) {
        return mArr.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.city_item, parent, false);
            holder = new ViewHolder();
            holder.tvName = (TextView) convertView.findViewById(R.id.city_item_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvName.setText(mArr.get(position).getName());
        return convertView;
    }

    private class ViewHolder {
        TextView tvName;
    }
}
